
import java.util.Arrays;
import java.util.Random;
public class Test {
    /**
     * 正序数组
     * @param array
     */
   public   static void inorderArray(int[] array){
       for (int i = 0; i < array.length; i++) {
           array[i] = i;
       }
   }


    /**
     * 逆序数组
     * @param array
     */
    public   static void notInorderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length-i;
        }
    }

    /**
     * 无序数组
     * @param array
     */
    public   static void initArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(array.length);
        }
    }


    /**
     * 插入排序测试
     * @param array
     */
    public static void testInsertSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序："+(endTime-startTime)+" ms");
    }

    public static void  testShellSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序 : " +  (endTime - startTime)+"ms");
    }

    public static  void testQuickSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序 :" + (endTime - startTime)+"ms");
    }
    public static  void testHeapSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序 :" + (endTime - startTime)+"ms");
    }
    public static  void testMergeSort(int[] array){
        int[] tmpArray = Arrays.copyOf(array, array.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序 :" + (endTime - startTime)+"ms");
    }


    public static void main(String[] args) {

//        int[] array = new int[1000];
//        int[] array = new int[10000]
//        int[] array = new int[10000];
        int[] array = new int[1000000];
//        notInorderArray(array); // 逆序
//        System.out.println("正序情况下:");
//        inorderArray(array);//正序
        initArray(array);//乱序
        System.out.println("乱序情况下:");
        testShellSort(array);
        testQuickSort(array);
        testInsertSort(array);
        testHeapSort(array);
        testMergeSort(array);
    }

}
